package com.slmxz.tms.document.controller;

import com.slmxz.tms.common.model.Query;
import com.slmxz.tms.common.result.PageResult;
import com.slmxz.tms.common.result.Result;
import com.slmxz.tms.common.support.Condition;
import com.slmxz.tms.document.model.entity.Truck;
import com.slmxz.tms.document.model.vo.DriverVO;
import com.slmxz.tms.document.model.vo.TruckVO;
import com.slmxz.tms.document.service.TruckService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 车辆信息前端控制层
 * @author sunyao
 * @Date 2024-11-15
 */
@Tag(name = "车辆信息接口")
@RestController
@RequestMapping("/document/truck")
@RequiredArgsConstructor
public class TruckController  {

    private final TruckService truckService;

    @Operation(summary = "车辆信息分页列表")
    @GetMapping("/page")
    public PageResult<TruckVO> selectTruckPage(Query query, TruckVO truck) {
        IPage<TruckVO> result = this.truckService.selectTruckPage(Condition.getPage(query),truck);
        return PageResult.success(result);
    }

    @Operation(summary = "车辆信息的下拉框")
    @GetMapping("/selectOption")
    public Result<?> selectOption(TruckVO truck){
        return Result.success(this.truckService.selectOption(truck));
    }

    @Operation(summary = "新增车辆信息")
    @PostMapping("/save")
    @PreAuthorize("@ss.hasPerm('document:truck:add')")
    public Result<Void> saveTruck(@RequestBody @Valid TruckVO  truck) throws Exception {
        boolean result = this.truckService.saveTruck(truck);
        return Result.result(result);
    }

    @Operation(summary = "获取车辆信息详情数据")
    @GetMapping("/detail/{id}")
    @PreAuthorize("@ss.hasPerm('document:truck:edit')")
    public Result<Truck> selectTruckDetail(
        @Parameter(description = "车辆信息ID") @PathVariable Long id
    ) {
        Truck truck = this.truckService.selectTruckDetail(id);
        return Result.success(truck);
    }

    @Operation(summary = "修改车辆信息")
    @PutMapping(value = "/update")
    @PreAuthorize("@ss.hasPerm('document:truck:edit')")
    public Result<Void> updateTruck(
            @RequestBody @Validated TruckVO truck
    ) throws Exception {
        boolean result = truckService.updateTruck(truck);
        return Result.result(result);
    }

    @Operation(summary = "删除车辆信息")
    @DeleteMapping("/remove/{ids}")
    @PreAuthorize("@ss.hasPerm('document:truck:delete')")
    public Result<Void> deleteTrucks(
        @Parameter(description = "车辆信息ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = this.truckService.deleteTrucks(ids);
        return Result.result(result);
    }

    @Operation(summary = "激活或者注销车辆信息")
    @PostMapping("/activeOrLogout")
    @PreAuthorize("@ss.hasPerm('document:business:delete')")
    public Result<Void> activeOrLogout(@RequestBody TruckVO truck) {
        boolean result = this.truckService.activeOrLogout(truck);
        return Result.result(result);
    }


}
